<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>onload</title>
   <style>
   </style>
   <script>
      function myAddEvent(obj,ev,fn){
	    if(obj.attachEvent){
		    obj.attachEvent('on'+ev,fn);
		}else{
		    obj.addEventListener(ev,fn);
		}
	  }
     
      window.onload=function(){
	    var oBtn=document.getElementById("btn1");
		myAddEvent(oBtn,'click',function(){
		    alert('a');
		});
		
	    /*if(oBtn.attachEvent){
		   oBtn.attachEvent('onclick',function(){
		  alert("a");
		  });
		  oBtn.attachEvent('onclick',function(){
		  alert("b");
		  });
		}else{
		  oBtn.addEventListener('click',function(){
		  alert('a');
		  },false);
		 oBtn.addEventListener('click',function (){
		  alert('b');
		 },false);		
		}*/	//attachEvent(事件名,函数)绑定事件，防止在同一个元素中两个事件会相互覆盖
		/*oBtn.attachEvent('onclick',function(){
		  alert("a");
		});
		oBtn.attachEvent('onclick',function(){
		  alert("b");
		});*/
		//FF
		//addEventListener(事件名,函数,false)
		/*oBtn.addEventListener('click',function(){
		  alert('a');
		},false);
		oBtn.addEventListener('click',function(){
		  alert('b');
		},false);*/
		/*oBtn.onclick=function(){
		   alert("a");
		}
		oBtn.onclick=function(){
		   alert("b");
		}*/
	  };

   </script>
</head>
<body>
    <input id="btn1" type="button" value="按钮"/>


</body>
</html>